var scope = "global scope";
function checkscope(){
    var scope = "local scope";
    function f(){
        console.log(scope);
        return scope;
    }
    return f;
}

var foo = checkscope();
console.log(foo);
console.log(foo());

var data = [];
for (var i = 0; i < 3; i++) {
  data[i] = (function (i) {
        return function(){
            console.log(i);
        }
  })(i);
}
data[0]();
data[1]();
data[2]();